package com.smforj.ssm.frame.core.aop; 

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint; 

import com.smforj.ssm.frame.core.dao.DbContextHolder;
import com.smforj.ssm.frame.core.enums.JDataSource;
import com.smforj.ssm.util.StringEx;

/**
 * 数据库源拦截器
 * 
 * 
 * @author Haijun Gao 
 * @date 2016-8-5 下午5:45:01
 * @desp http://www.cnblogs.com/saga5998/
 * @email 573107773@qq.com
 */ 
public class DataSourceAop {
	private Logger log = Logger.getLogger(DataSourceAop.class); 
	 
	public void setDataSource(JoinPoint jp) { 
	      //获取目标对象对应的类名     
        String className = jp.getTarget().getClass().getName();     
        //获取目标对象上正在执行的方法名     
        String methodName = jp.getSignature().getName();  
        System.out.println("前置通知:" + className + "类的" + methodName + "方法开始了"+jp.getArgs());  
         
        JDataSource ds = jp.getTarget().getClass().getAnnotation(JDataSource.class); 
        if(ds==null || StringEx.isExEmpty(ds.value()))
        {
        	DbContextHolder.setCustomerType("mdefault");
        	log.info("setDataSource......mdefault");  
        }
        else
        {
        	DbContextHolder.setCustomerType(ds.value()); 
        	log.info("setDataSource......"+ds.value());  
        }
	}  

}
